﻿using UnityEngine;
using UnityEngine.UI;

[DisallowMultipleComponent]
public class UILangSwitch : MonoBehaviour
{
	[System.Serializable]
	public class LangItem
	{
		public string lang;
		public Transform item;
	}

	public LangItem[] items;
	
    void Awake()
	{
		if (items != null && items.Length > 0) {
			LangItem itemDefault = null;
			LangItem item = null;
			bool found = false;
			for (int i = 0; i < items.Length; ++i) {
				item = items [i];
				if (string.Equals (item.lang, Config.Instance.Language)) {
					found = true;
					item.item.SetActive (true);
				} else {
					item.item.SetActive (false);
				}

				if (itemDefault == null && string.Equals (item.lang, "en")) {
					itemDefault = item;
				}
			}

			if (!found) {
				if (itemDefault != null) {
					item = itemDefault;
				} else {
					item = items [items.Length - 1];
				}
				item.item.SetActive (true);
			}
		}
	}
}